package com.sgb.member.ui.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.sgb.member.BR;
import com.sgb.member.R;
import com.sgb.member.databinding.ItemMemberDemandBinding;
import com.sgb.member.databinding.ItemMemberDemandLeaseBinding;
import com.sgb.member.entity.MemberDemandBean;
import com.sgb.member.entity.MemberDemandLeaseBean;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DateUtils;
import com.swgk.core.util.StringUtil;

import java.util.List;

/**
 * Time:2021/4/30
 * AUTHOR:F_Q
 * Description:
 */
public class MemberDemandLeaseAdapter extends BaseRecycleAdapter<MemberDemandLeaseBean> {

    public MemberDemandLeaseAdapter(Context context, int curPage, List<MemberDemandLeaseBean> datas) {
        super(context, R.layout.item_member_demand_lease, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, MemberDemandLeaseBean entity) {
        ItemMemberDemandLeaseBinding binding = (ItemMemberDemandLeaseBinding) holder.getmBinding();
        holder.setBinding(BR.itemBean, entity);
        binding.tvRentalPrice.setText(entity.getPrice());
        if (StringUtil.isEmpty(entity.getRentalDuration())) {
            binding.tvRentalDuration.setText("面议");
        } else {
            if (entity.getRentalDuration().startsWith("-1")) {
                binding.tvRentalDuration.setText("面议");
            } else {
                binding.tvRentalDuration.setText(entity.getRentalDuration());
            }
        }
        binding.tvRentalNumber.setText(StringUtil.isEmpty(entity.getNumOrArea()) ? "" : entity.getNumOrArea());
        if (!StringUtil.isEmpty(entity.getUpdatetime())) {
            String s = DateUtils.timestampToDateSecond(Long.parseLong(entity.getUpdatetime()));
            binding.tvRentalTime.setText(s);
        } else {
            binding.tvRentalTime.setText("/");
        }
        if (!StringUtil.isEmpty(entity.getEndTime())) {
            String s = DateUtils.timestampToDateSecond(Long.parseLong(entity.getEndTime()));
            binding.tvRentalEndTime.setText(String.format("%s截止", s));
        } else {
            binding.tvRentalEndTime.setText("");
        }
        binding.tvAddress.setText(StringUtil.isEmpty(entity.getAddress()) ? "" : entity.getAddress());
        String rentSeekCategory = "";
        switch (entity.getType()) {
            case 1: // 机械租赁
                rentSeekCategory = "机械租赁";
                break;
            case 2: // 1设备租赁
                rentSeekCategory = "设备租赁";
                break;
            case 3: // 2车辆租赁
                rentSeekCategory = "车辆租赁";
                break;
            case 4: // 3房产租赁
                rentSeekCategory = "房产租赁";
                break;
            case 5: // 4土地租赁
                rentSeekCategory = "土地租赁";
                break;
            case 6: // 5工厂租赁
                rentSeekCategory = "工厂租赁";
                break;
            case 7: // 农机租赁
                rentSeekCategory = "农机租赁";
                break;
        }
        if (TextUtils.isEmpty(rentSeekCategory)) {
            binding.tvCategory.setVisibility(View.GONE);
        } else {
            binding.tvCategory.setVisibility(View.VISIBLE);
        }
        binding.tvCategory.setText(rentSeekCategory);
    }
}
